package Group9.TodoManager;

import java.awt.Component;
import javax.swing.JSlider;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

/**
 * Slider for table model
 * @author Rupesh
 * @author volkan cambazoglu
 */
public class SliderTableCell extends JSlider implements TableCellRenderer {
	
	/**
	 * Default constructor of the class
	 * creates an instance of the class by doing initialization
	 */
    public SliderTableCell() {
        super();
        this.setMajorTickSpacing(1);
        this.setMinorTickSpacing(1);
        this.setMinimum(0);
        this.setMaximum(2);
    }

    /**
     * This method is used to get the component of the cell renderer.
     * Attributes such as background and foreground of the component are
     * set.
     * @param table the table that the component belongs to
     * @param value
     * @param isSelected boolean value that represents if the component is selected
     * @param hasFocus boolean value that represents if the component is focused
     * @param row the row of the table
     * @param column the column of the table
     * @return component the component to be retreived
     */
    public Component getTableCellRendererComponent(JTable table, Object value, 
    			  boolean isSelected, boolean hasFocus, int row, int column) {
                  
          this.setValue(Integer.parseInt((String)value));
          if(isSelected) {
              setForeground(table.getSelectionForeground());
              super.setBackground(table.getSelectionBackground());
          }
          else {
            setForeground(table.getForeground());
            setBackground(table.getBackground());
          }
          this.updateUI();
          return this;	      
    }

    /**
     * Getter method of the cell editor value
     * @return value the value
     */
    public Object getCellEditorValue() {
        return this.getValue();
    }   
}
